import 'package:flutter/material.dart';

import '../models.dart';
import '../typedefs.dart';

class DetailScreen extends StatelessWidget {
  final Todo todo;
  final TodoRemove todoDelete;
  const DetailScreen({super.key, required this.todo, required this.todoDelete});

  void _showDeleteConfirmation(BuildContext context) {
    bool isUndo = false;
    final snackBar = SnackBar(
      content: Text('删除任务'),
      duration: Duration(seconds: 3),
      action: SnackBarAction(
        label: '撤销',
        onPressed: () {
          isUndo = true;
        },
      ),
    );
    ScaffoldMessenger.of(context).showSnackBar(snackBar).closed.then((value) {
      if (!isUndo) {
        todoDelete(todo);
        Navigator.pop(context);
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(todo.task),
        actions: [
          IconButton(
            onPressed: () => _showDeleteConfirmation(context),
            icon: Icon(Icons.delete),
          ),
        ],
      ),
      body: Center(child: Text(todo.note)),
      floatingActionButton: FloatingActionButton(onPressed: () {}),
    );
  }
}
